package com.example.apple.toast;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
/**
 * 1、AlertDialog是一个信息提示框，当出现是，需要用户点击，才会消失
 2、Toast也是一个信息提示框，出现后会更具设定的时间，自动消失
 *
 * **/

public class MessageActivity extends Activity {
    //定义变量
    private Button alert = null;
    private Button toast = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //根据Id得到控件对象
        alert = (Button)findViewById(R.id.alert);
        toast = (Button)findViewById(R.id.toast);

        //给按钮设定单击事件监听器
        alert.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                //显示AlertDialog
                new AlertDialog.Builder(MessageActivity.this).setTitle("MessageDemo").setMessage("Err").setNeutralButton("close", new DialogInterface.OnClickListener() {

                    //点击AlertDialog上的按钮的事件处理代码
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        System.out.println("what fuck");

                    }
                }).show();

            }
        });
        toast.setOnClickListener(new View.OnClickListener() {

            //显示Toast
            @Override
            public void onClick(View v) {

                Toast.makeText(MessageActivity.this, "<Clink,Clink>", Toast.LENGTH_SHORT).show();

            }
        });
    }
}